<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>待办列表</title>

    <!-- BOOTSTRAP STYLES-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet"/>
    <!--CUSTOM BASIC STYLES-->
    <link href="../assets/css/basic.css" rel="stylesheet"/>
    <!--CUSTOM MAIN STYLES-->
    <link href="../assets/css/custom.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="wrapper">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <h6 class="page-subhead-line">线路管理</h6>
            </div>
        </div>


        <div class="row">
            <div class="col-md-12">
                <!--   Kitchen Sink -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        *****
                    </div>
                    <div class="panel-body">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <div class="col-sm-2">
                                    <label for="lineCode">线路编号：</label>
                                    <input type="text" class="form-control" id="lineCode" placeholder="请输入任务编号">
                                </div>
                                <div class="col-sm-2">
                                    <label for="runningStatusName">线路状态</label>
                                    <select class="form-control" id="runningStatusName" name="runningStatusName">
                                        <option value="">--请选择--</option>
                                        <option value="正常">正常</option>
                                        <option value="检修中">检修中</option>
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <label for="lineCode">数据：</label>
                                    <input disabled type="text" class="form-control" id="lineNum">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-1">
                                    <button class="btn btn-info col-sm-12" id="submitLine">查询</button>
                                </div>
                                <div class="col-sm-1">
                                    <button class="btn btn-info col-sm-12" id="EmptyLine">清空</button>
                                </div>
                            </div>
                        </div>

                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>线路编号</th>
                                    <th>线路名称</th>
                                    <th>起始杆号</th>
                                    <th>终止杆号</th>
                                    <th>塔基数</th>
                                    <th>运行状态</th>
                                    <th>启用状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="userlist"></tbody>
                            </table>
                            <ul class="pagination">
                                <li>
                                    <a href="">首页</a>
                                </li>
                                <li>
                                    <a href="">&laquo;</a>
                                </li>
                                <li>
                                    <a></a>
                                </li>
                                <li>
                                    <a href="">&raquo;</a>
                                </li>
                                <li>
                                    <a href="">末页</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- End  Kitchen Sink -->
            </div>

        </div>

    </div>

</div>


<!-- /. FOOTER  -->
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<!-- JQUERY SCRIPTS -->
<script src="../assets/js/jquery.min.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="../assets/js/bootstrap.min.js"></script>
<script type="application/javascript">

    $(function () {
        getPage(1);
        $("#submitLine").click(function () {
            getPage(1);
        })
    })

    function getPage(pageNo) {
        var lineCode = $("#lineCode").val().trim();
        var runningStatusName = $("#runningStatusName").val().trim();
        $.ajax({
                url: "http://localhost:8080/lineinfo/alllineinfo",
                type: "get",
                data: {
                    "currentPage": pageNo,
                    "runningStatusName": runningStatusName,
                    "lineCode": lineCode
                },
                dataType: "json",
                success: function (data) {
                    if (data.status == 200 && data.obj.lists != null) {
                        $("#userlist").html("");
                        var pageNum = data.obj.currPage;//当前页数
                        var totalPages = data.obj.totalPage;//总页数
                        var totalCount = data.obj.totalCount;//总页数
                        $("#lineNum").val(totalCount + "条数据")
                        var list = data.obj.lists;//每页的显示的数据
                        for (var i = 0; i < list.length; i++) {
                            var lineInfoId = list[i].id;
                            var lineCode = list[i].lineCode;
                            var lineName = list[i].lineName;
                            var startPoleCode = list[i].startPoleCode;
                            var endPoleCode = list[i].startPoleCode;
                            var towerBaseNum = list[i].towerBaseNum;
                            var runningStatusName = list[i].runningStatusName;
                            var isStart = list[i].isStart;
                            //数据处理
                            var caozuo = "";
                            var isStarts = 0;
                            if (isStart == 1) {
                                isStart = '启用';
                                isStarts = 0;
                                caozuo = "<a class='btn btn-success' href='javascript: runningchange(" + lineInfoId + ",\"" + isStarts + "\")'>停用</a>&nbsp;&nbsp;" +
                                    "<a  class='btn btn-success'>修改</a>&nbsp;&nbsp;" +
                                    "<a  class='btn btn-success'>删除</a>"
                            } else if (isStart == 0) {
                                isStart = '停止';
                                isStarts = 1;
                                caozuo = "<a class='btn btn-success' href='javascript: runningchange(" + lineInfoId + ",\"" + isStarts + "\")'>启用</a>&nbsp;&nbsp;" +
                                    "<a  class='btn btn-success'>修改</a>&nbsp;&nbsp;" +
                                    "<a  class='btn btn-success'>删除</a>"
                            }
                            var tr = "<tr>" +
                                "<td>" + lineCode + "</td>" +
                                "<td>" + lineName + "</td>" +
                                "<td>" + startPoleCode + "</td>" +
                                "<td>" + endPoleCode + "</td>" +
                                "<td>" + towerBaseNum + "</td>" +
                                "<td>" + runningStatusName + "</td>" +
                                "<td>" + isStart + "</td>" +
                                "<td>" + caozuo + "</td>" + "</tr>";
                            $("#userlist").append(tr);
                        }


                        /* 按钮换页 */
                        $(".pagination li:eq(0) a").attr("href", "javascript:getPage(1)");
                        $(".pagination li:eq(1) a").attr("href", "javascript:getPage(" + (pageNum - 1) + ")");
                        $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + (pageNum + 1) + ")");
                        $(".pagination li:eq(4) a").attr("href", "javascript:getPage(" + totalPages + ")");

                        if (pageNum <= 1) {
                            $(".pagination li:eq(1) a").attr("href", "javascript:getPage(1)");

                        } else if (pageNum >= totalPages) {
                            $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + totalPages + ")");
                        }
                        //当前页和总页数的显示

                        $(".pagination li:eq(2) a").html(pageNum + "/" + totalPages + "页");

                    } else if (data.status == 500 && data.msg) {
                        alert(data.msg);
                    }
                },
                error: function () {
                    console.log("与后台断开连接！！！");
                }
            }
        )
    }


    function runningchange(lineInfoId, isStarts) {
        $.ajax({
            url: "http://localhost:8080/lineinfo/runningchange",
            type: 'get',
            data: {
                "id": lineInfoId,
                "isStart": isStarts
            },
            dataType: "json",
            success: function (data) {

                if (data.obj == 1) {
                    alert(data.msg);
                    window.location.href = 'LineManagement.html';
                }
            },
            error: function () {
                alert("error")
            }
        })


    }
</script>


</body>
</html>
